# mysql
import pymysql

conn = pymysql.Connect(
    host='192.168.88.100',
    port=3306,
    user='root',
    password='123456',
    db='tedu',
    charset='utf8'
)

cur = conn.cursor()

create_sql = '''
    create table dept(
        did int,
        dname varchar(16)
    )
'''
cur.execute(create_sql)
#
insert_sql = 'insert into dept values(1, "yafa")'
cur.execute(insert_sql)
insert_sql = 'insert into dept values(2, "yunwei")'
cur.execute(insert_sql)
#
select_sql = 'select * from dept'
cur.execute(select_sql)
one = cur.fetchone()
print(one)
many = cur.fetchmany(2)
print(many)
all = cur.fetchall()
print(all)
#
update_sql = 'update dept set dname=%s where did=%s'
cur.execute(update_sql, ('caiwu', 1))
cur.executemany(update_sql, [('renli', 2), ('dou', 3)])
#
delete_sql = 'delete from dept where did=%s'
cur.execute(delete_sql, (2, ))
cur.executemany(delete_sql, [(1, ), (3, )])



insert_sql = 'insert into dept values(%s, %s)'
cur.execute(insert_sql, (3, 'yunwei'))
cur.executemany(insert_sql, [(4, 'ceshi'), (5, 'seji'), (6, 'yunying')])




conn.commit()
cur.close()
conn.close()
